package com.tjbklx1.thread.chap03.practise06;

import java.util.Random;

public class ClientThread extends Thread {

	private final Random random;

	private final RequestQueue requestQueue;

	public ClientThread(String name, RequestQueue requestQueue, long seed) {
		super(name);
		this.random = new Random(seed);
		this.requestQueue = requestQueue;
	}

	@Override
	public void run() {
		try {
			for (int i = 0; i < 10000; i++) {
				Request request = new Request("No." + i);
				System.out.println(Thread.currentThread().getName()
						+ " Requests " + request);
				requestQueue.putRequest(request);
				Thread.sleep(random.nextInt(100));
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}
